package bradd.Blackjack;




import java.lang.reflect.Array;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.GetChars;
import android.text.InputType;
import android.text.method.KeyListener;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;



public class Table extends Activity implements OnClickListener {
	
	Deck deal;
	ArrayList<Card> m_dealer;
	ArrayList<Card> m_player;
	ArrayList<Card> hand;
	ArrayList<Card> s_player;
	ImageView[] playerimg;
	ImageView[] dealerimg;
	ImageView[] hitimg;
	ImageView[] dealhitimg;
	ImageView[] splitplayerimg;
	int[] m_cardIds;
	Player player;
	
	
	

@Override	
public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.table);

        getWindow().setBackgroundDrawableResource(R.drawable.felt);
        
        final EditText editbet = (EditText)findViewById(R.id.bet);
        editbet.setInputType(InputType.TYPE_CLASS_NUMBER);

//            editbet.setKeyListener(new KeyListener(){
//			
//			
//			
//
//			@Override
//			public void clearMetaKeyState(View view, Editable content,
//					int states) {
//				// TODO Auto-generated method stub
//				
//			}
//
//			@Override
//			public int getInputType() {
//				
//				return 2;
//			}
//
//			@Override
//			public boolean onKeyDown(View view, Editable text, int KEYCODE_ENTER,
//					KeyEvent event) {
//				int bet = Integer.parseInt(editbet.getText().toString());
//				int stack = player.getStack();
//				int newstack = stack - bet;
//				player.setStack(newstack);
//				player.setBet(bet);
//				showbet();
//				return true;
//			}
//
//			@Override
//			public boolean onKeyOther(View view, Editable text, KeyEvent event) {
//				// TODO Auto-generated method stub
//				return false;
//			}
//
//			@Override
//			public boolean onKeyUp(View view, Editable text, int KEYCODE_ENTER,
//					KeyEvent event) {
//				   ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
//				   .hideSoftInputFromWindow(editbet.getWindowToken(), 0);  
//
//				return true;
//				
//			}
//		}
//        );	
        
        

        Button button2 = (Button) findViewById(R.id.back);
        button2.setOnClickListener(this);
        
        Button button3 = (Button) findViewById(R.id.sum);
        button3.setOnClickListener(new View.OnClickListener() {
        	
			@Override
			public void onClick(View v) {
				sumtoast();
				
			}	
        }
        )	
        ;

        Button button4 = (Button) findViewById(R.id.hit);
        button4.setVisibility(8);
        button4.setOnClickListener(new View.OnClickListener(){
        	@Override
        	public void onClick(View v){
        		hit();
        	}
        }
        )
        ;
        
        Button button5 = (Button) findViewById(R.id.stay);
        button5.setVisibility(8);
        button5.setOnClickListener(new View.OnClickListener(){
        	@Override
        	public void onClick(View v){
        		stay();
        	}
        }
        )
        ;
        Button button6 = (Button) findViewById(R.id.deal);
        button6.setVisibility(8);
        button6.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (m_player.size() == 0)
				{initiategame();}
				else
				if (m_player.size() != 0)
				{cleargame();}
				
			}
		});
        
        Button button7 = (Button)findViewById(R.id.doubledown);
        button7.setVisibility(8);
        button7.setOnClickListener(new View.OnClickListener(){
            	@Override
            	public void onClick(View v){
            		doubledown();
            	}
            }
            )
            ;
        
        Button button8 = (Button)findViewById(R.id.split);
        button8.setVisibility(8);
        button8.setOnClickListener(new View.OnClickListener(){
            	@Override
            	public void onClick(View v){
            		split();
                		
            	}
            }
            )
            ;
        Button button9 = (Button) findViewById(R.id.splithit);
        button9.setVisibility(8);
        button9.setOnClickListener(new View.OnClickListener(){
        	@Override
        	public void onClick(View v){
        		splithit();
        	}
        }
        )
        ;
        
        Button button10 = (Button) findViewById(R.id.splitstay);
        button10.setVisibility(8);
        button10.setOnClickListener(new View.OnClickListener(){
        	@Override
        	public void onClick(View v){
        		splitstay();
        	}
        }
        )
        ;
        Button button11 = (Button)findViewById(R.id.splitdoubledown);
        button11.setVisibility(8);
        button11.setOnClickListener(new View.OnClickListener(){
            	@Override
            	public void onClick(View v){
            		splitdoubledown();  
            	}
            }
            )
            ;
        
        Button button12 = (Button)findViewById(R.id.splitsplit);
        button12.setVisibility(8);
        button12.setOnClickListener(new View.OnClickListener(){
            	@Override
            	public void onClick(View v){
            		//splitsplit();
            	}
            }
            )
            ;
        Button button13 = (Button)findViewById(R.id.setbet);
        button13.setOnClickListener(new View.OnClickListener(){
        	@Override
        	public void onClick(View v){
        		setbet();
        		Button button6 = (Button)findViewById(R.id.deal);
        		button6.setVisibility(0);
        		
        	}
        }
        )
        ;
        
 
        InitMembers();
        
//        NewGame();
        
        
        m_cardIds = new int[52];
        m_cardIds[0] = R.drawable.card_1;
        m_cardIds[1] = R.drawable.card_2;
        m_cardIds[2] = R.drawable.card_3;
        m_cardIds[3] = R.drawable.card_4;
        m_cardIds[4] = R.drawable.card_49;
        m_cardIds[5] = R.drawable.card_50;
        m_cardIds[6] = R.drawable.card_51;
        m_cardIds[7] = R.drawable.card_52;
        m_cardIds[8] = R.drawable.card_45;
        m_cardIds[9] = R.drawable.card_46;
        m_cardIds[10] = R.drawable.card_47;
        m_cardIds[11] = R.drawable.card_48;
        m_cardIds[12] = R.drawable.card_41;
        m_cardIds[13] = R.drawable.card_42;
        m_cardIds[14] = R.drawable.card_43;
        m_cardIds[15] = R.drawable.card_44;
        m_cardIds[16] = R.drawable.card_37;
        m_cardIds[17] = R.drawable.card_38;
        m_cardIds[18] = R.drawable.card_39;
        m_cardIds[19] = R.drawable.card_40;
        m_cardIds[20] = R.drawable.card_33;
        m_cardIds[21] = R.drawable.card_34;
        m_cardIds[22] = R.drawable.card_35;
        m_cardIds[23] = R.drawable.card_36;
        m_cardIds[24] = R.drawable.card_29;
        m_cardIds[25] = R.drawable.card_30;
        m_cardIds[26] = R.drawable.card_31;
        m_cardIds[27] = R.drawable.card_32;
        m_cardIds[28] = R.drawable.card_25;
        m_cardIds[29] = R.drawable.card_26;
        m_cardIds[30] = R.drawable.card_27;
        m_cardIds[31] = R.drawable.card_28;
        m_cardIds[32] = R.drawable.card_21;
        m_cardIds[33] = R.drawable.card_22;
        m_cardIds[34] = R.drawable.card_23;
        m_cardIds[35] = R.drawable.card_24;
        m_cardIds[36] = R.drawable.card_17;
        m_cardIds[37] = R.drawable.card_18;
        m_cardIds[38] = R.drawable.card_19;
        m_cardIds[39] = R.drawable.card_20;
        m_cardIds[40] = R.drawable.card_13;
        m_cardIds[41] = R.drawable.card_14;
        m_cardIds[42] = R.drawable.card_15;
        m_cardIds[43] = R.drawable.card_16;
        m_cardIds[44] = R.drawable.card_9;
        m_cardIds[45] = R.drawable.card_10;
        m_cardIds[46] = R.drawable.card_11;
        m_cardIds[47] = R.drawable.card_12;
        m_cardIds[48] = R.drawable.card_5;
        m_cardIds[49] = R.drawable.card_6;
        m_cardIds[50] = R.drawable.card_7;
        m_cardIds[51] = R.drawable.card_8;


	}

	@Override
	public void onClick(View v) {
		super.onStop();
		Intent goback = new Intent(Table.this, Blackjack.class);
		Table.this.startActivity(goback);
		
	}
	public void initiategame()
	
   {
		Button button6 = (Button)findViewById(R.id.deal);
		button6.setVisibility(8);
		
		Button button4 = (Button)findViewById(R.id.hit);
	    button4.setVisibility(0);
	    
	    Button button5 = (Button)findViewById(R.id.stay);
	    button5.setVisibility(0);
	    
	    Button button7 = (Button)findViewById(R.id.doubledown);
	    button7.setVisibility(0);
		
			RelativeLayout rl = (RelativeLayout)findViewById(R.id.table1);
	        int width = rl.getWidth();
	        int maxWidth = width / 5;
	        
	        playerimg= new ImageView[5];
	        playerimg[0] = (ImageView)findViewById(R.id.playercard1);
	        playerimg[1] = (ImageView)findViewById(R.id.playercard2);
//	        playerimg[2] = (ImageView)findViewById(R.id.playercard3);
//	        playerimg[3] = (ImageView)findViewById(R.id.playercard4);
//	        playerimg[4] = (ImageView)findViewById(R.id.playercard5);
	        
	        
	        playerimg[0].setMaxWidth(maxWidth);
	        playerimg[1].setMaxWidth(maxWidth);
//	        playerimg[2].setMaxWidth(maxWidth);
//	        playerimg[3].setMaxWidth(maxWidth);
//	        playerimg[4].setMaxWidth(maxWidth);
	        
	       
	        
	        
	        dealerimg= new ImageView[6];
	        dealerimg[0]= (ImageView)findViewById(R.id.dealerdown);
	        dealerimg[1]= (ImageView)findViewById(R.id.dealercard1);
	        dealerimg[2]= (ImageView)findViewById(R.id.dealercard0);
	        dealerimg[3]= (ImageView)findViewById(R.id.dealercard2);
	        dealerimg[4]= (ImageView)findViewById(R.id.dealercard3);
	        dealerimg[5]= (ImageView)findViewById(R.id.dealercard4);
	  
	        
	        dealerimg[0].setMaxWidth(maxWidth);
	        dealerimg[1].setMaxWidth(maxWidth);
	        dealerimg[2].setMaxWidth(maxWidth);
	        dealerimg[3].setMaxWidth(maxWidth);
	        dealerimg[4].setMaxWidth(maxWidth);
	        dealerimg[4].setMaxWidth(maxWidth);
	        dealerimg[4].setMaxWidth(maxWidth);

	      
	        
	        dealerimg[0].setImageResource(R.drawable.card_b1fv);
	        
	        deal.Shuffle();
	        {
	       for (int dsize = m_dealer.size(); dsize < 2; dsize++)
	       	m_dealer.add(deal.DealCard());
//	        for (int psize = m_player.size(); psize < 2; psize++)
//	        	m_player.add(deal.DealCard());
	        }
	        

	        for (int i = 1; i < m_dealer.size(); i++)
	        	{dealerimg[i].setImageResource(m_cardIds[m_dealer.get(i).getValue() * 4 + m_dealer.get(i).getSuit()]);	}
	        
	        DealToPlayers();
	        checkdealerblackjack();
	        checkblackjack();
	        checkSplit();

		}
		
	public void cleargame(){
		{
			Button button6 = (Button)findViewById(R.id.deal);
			button6.setVisibility(8);
			
			Button button4 = (Button)findViewById(R.id.hit);
		    button4.setVisibility(0);
		    
		    Button button5 = (Button)findViewById(R.id.stay);
		    button5.setVisibility(0);
		    
		    Button button7 = (Button)findViewById(R.id.doubledown);
		    button7.setVisibility(0);
			
			for (int i=2; i<m_player.size(); i++)
				{playerimg[i].setImageResource(0);}
			
			for (int i=0; i<m_dealer.size()+1; i++)
				{dealerimg[i].setImageResource(0);}
			
			if (s_player.size()>0){
				for (int i=0; i<s_player.size(); i++)
				{splitplayerimg[i].setImageResource(0);}
			
			Button button10 = (Button)findViewById(R.id.splithit);
		    button10.setVisibility(8);
		    
		    Button button11 = (Button)findViewById(R.id.splitstay);
		    button11.setVisibility(8);
		    
		    Button button12 = (Button)findViewById(R.id.splitdoubledown);
		    button12.setVisibility(8);
			}
			
			
			dealerimg[0].setImageResource(R.drawable.card_b1fv);
			m_player.clear();
			m_dealer.clear();
			s_player.clear();
			deal.Shuffle();
		}
        {
       for (int dsize = m_dealer.size(); dsize < 2; dsize++)
       	m_dealer.add(deal.DealCard());
//        for (int psize = m_player.size(); psize < 2; psize++)
//        	m_player.add(deal.DealCard());
        } 

        for (int i = 1; i < m_dealer.size(); i++)
        	{dealerimg[i].setImageResource(m_cardIds[m_dealer.get(i).getValue() * 4 + m_dealer.get(i).getSuit()]);	}
        
        DealToPlayers();
        checkdealerblackjack();
        checkblackjack();
        checkSplit();
        
		}
		
    
	
	
	 private void InitMembers()
	    {
	    	deal = new Deck();
	    	m_dealer = new ArrayList<Card>();
	    	m_player = new ArrayList<Card>();
	    	s_player = new ArrayList<Card>();
	    	player = new Player(0);
	    	int stack = 1500;
	    	player.setStack(stack);
    	  
	    }
	 
	 private void inputbet()
	 	{
	 		int x=1;
	 	}
	 	
	
	 private void DealToPlayers()
	    {
		 for (int i = 0; i < 2; i++){
 			{m_player.add(deal.DealCard());}
		 }
		 for (int i = 0; i < m_player.size(); i++){
     		{playerimg[i].setImageResource(m_cardIds[m_player.get(i).getValue() * 4 + m_player.get(i).getSuit()]);}
		 }
		 aces();
	    	
	    }
	 private void NewGame()
	    {
		 	deal.Shuffle();
	    	DealToPlayers();
	    }
	public int getsum()
	{

    
	int sum = 0;
	for(int i=0; i < m_player.size(); i++) 
		{sum += (m_player.get(i).getScore());}
		
		
	return sum;
	 
	}
	private int getdealersum()
	{

    
	int sum = 0;
	for(int i=0; i < m_dealer.size(); i++) 
		{sum += (m_dealer.get(i).getScore());}
		
		
	return sum;
	 
	}
	private int getsplitsum()
	{

    
	int sum = 0;
	for(int i=0; i < s_player.size(); i++) 
		{sum += (s_player.get(i).getScore());}
		
		
	return sum;
	 
	}
	private void sumtoast()
	{
		 Toast t = Toast.makeText(this, String.format("%d", getsum() ), Toast.LENGTH_SHORT);
         t.show();

	}
	private void blackjack()
	{
		Toast m = Toast.makeText(this,"Blackjack!",Toast.LENGTH_SHORT);
		m.show();
	}
	private void checkblackjack()
	{
		
		if (getsum() == 21){
			blackjack();
			playerwins();
		}
		else sumtoast();
	}
	private void checkdealerblackjack()
	{
		
		if (getdealersum() == 21){
			dealerwins();
		}
		else sumtoast();
	}
	public void hit()
	{
		
		
		if (m_player.size() == 2)
		{
			m_player.add(deal.DealCard());
			playerimg[2] = (ImageView)findViewById(R.id.playercard3);
			playerimg[2].setImageResource(m_cardIds[m_player.get(2).getValue() * 4 + m_player.get(2).getSuit()]);
			checkscore();
			sumtoast();
		}
		else
		if (m_player.size() == 3){
			m_player.add(deal.DealCard());
			playerimg[3] = (ImageView)findViewById(R.id.playercard4);
			playerimg[3].setImageResource(m_cardIds[m_player.get(3).getValue() * 4 + m_player.get(3).getSuit()]);
			checkscore();
			sumtoast();
		}
		else
		if (m_player.size() == 4){
			m_player.add(deal.DealCard());
			playerimg[4] = (ImageView)findViewById(R.id.playercard5);
			playerimg[4].setImageResource(m_cardIds[m_player.get(4).getValue() * 4 + m_player.get(4).getSuit()]);
			checkscore();
			sumtoast();
		}
		aces();
		
	}
	public void dealerhit()
	{
		if (m_dealer.size() == 2)
		{
			m_dealer.add(deal.DealCard());
			dealerimg[3] = (ImageView)findViewById(R.id.dealercard2);
			dealerimg[3].setImageResource(m_cardIds[m_dealer.get(2).getValue() * 4 + m_dealer.get(2).getSuit()]);
			
		}
		else
		if (m_dealer.size() == 3){
			m_dealer.add(deal.DealCard());
			dealerimg[4] = (ImageView)findViewById(R.id.dealercard3);
			dealerimg[4].setImageResource(m_cardIds[m_dealer.get(3).getValue() * 4 + m_dealer.get(3).getSuit()]);
			
		}
		else
		if (m_dealer.size() == 4){
			m_dealer.add(deal.DealCard());
			dealerimg[5] = (ImageView)findViewById(R.id.dealercard4);
			dealerimg[5].setImageResource(m_cardIds[m_dealer.get(4).getValue() * 4 + m_dealer.get(4).getSuit()]);
			
		}
		

		stay();
	}
	public void splithit()
	{
		
		
		if (s_player.size() == 2)
		{
			s_player.add(deal.DealCard());
			splitplayerimg[2] = (ImageView)findViewById(R.id.splitplayercard3);
			splitplayerimg[2].setImageResource(m_cardIds[s_player.get(2).getValue() * 4 + s_player.get(2).getSuit()]);
			checkscore();
			sumtoast();
		}
		else
		if (s_player.size() == 3){
			s_player.add(deal.DealCard());
			splitplayerimg[3] = (ImageView)findViewById(R.id.splitplayercard4);
			splitplayerimg[3].setImageResource(m_cardIds[s_player.get(3).getValue() * 4 + s_player.get(3).getSuit()]);
			checkscore();
			sumtoast();
		}
		else
		if (s_player.size() == 4){
			s_player.add(deal.DealCard());
			splitplayerimg[4] = (ImageView)findViewById(R.id.splitplayercard5);
			splitplayerimg[4].setImageResource(m_cardIds[s_player.get(4).getValue() * 4 + s_player.get(4).getSuit()]);
			checkscore();
			sumtoast();
		}
		
		
	}
	private void checkscore()
	{
	aces();
	if (getdealersum() == 21){
	Toast l = Toast.makeText(this, "Dealer Wins!", Toast.LENGTH_SHORT);
	l.show();
	}
	else{
	int score = getsum();
	if (score == 21)
	{blackjack();}
	if (score <= 21)
	{sumtoast();}
	if (score > 21)
	{bust();}
	}
	}
	
	private void bust()
	{
		int lbet = player.getBet();
		int newstack = player.getBet() - lbet;
		player.setStack(newstack);
		
		
	Toast b = Toast.makeText(this, "Bust! Player loses" + lbet , Toast.LENGTH_SHORT);
	b.show();

	}
	public void stay()
	{
		Button button4 = (Button)findViewById(R.id.hit);
	    button4.setVisibility(8);
	    
	    Button button5 = (Button)findViewById(R.id.stay);
	    button5.setVisibility(8);
	    
	    Button button7 = (Button)findViewById(R.id.doubledown);
	    button7.setVisibility(8);
	    
	    Button button6 = (Button)findViewById(R.id.deal);
		button6.setVisibility(8);
	    
	if (s_player.size() == 0)
	{
	dealerimg[2].setImageResource(m_cardIds[m_dealer.get(0).getValue() * 4 + m_dealer.get(0).getSuit()]);		
	int dealscore = getdealersum();
	
	
	if (dealscore <= 17)
	{dealerhit();}
	if (dealscore > 21)
	{playerwins();}
	if (dealscore <= 21 && dealscore > 17)
	{showdown();}
	}
	if (s_player.size() != 0)
	{
		Button button10 = (Button)findViewById(R.id.splithit);
	    button10.setVisibility(0);
	    
	    Button button11 = (Button)findViewById(R.id.splitstay);
	    button11.setVisibility(0);
	    
	    Button button12 = (Button)findViewById(R.id.splitdoubledown);
	    button12.setVisibility(0);
	}
	}
	
	private void showdown()
	{
	int dealscore = getdealersum();
	int playscore = getsum();
	
	if (playscore > dealscore )
	{playerwins();}
	if (dealscore > playscore)
	{dealerwins();}
	if (dealscore == playscore)
	{push();}
	}
	private void playerwins()
	{
		int lbet = player.getBet();
		int newstack = (lbet*2)+player.getStack();
		player.setStack(newstack);
		Toast pw = Toast.makeText(this, "Win" + (lbet*2) + "     Player now has     " + (newstack), Toast.LENGTH_SHORT);
		pw.show();
	
	}
	private void dealerwins()
	{
		int newstack = player.getStack();
		player.setStack(newstack);
	
		Toast pw = Toast.makeText(this, "Dealer Wins!!" + "Player loses" + player.getBet() + "  Player now has " + player.getStack(), Toast.LENGTH_SHORT);
		pw.show();

	}
	private void push()
	{
		int lbet = player.getBet();
		int newstack = player.getStack() + lbet;
		player.setStack(newstack);
		Toast pw = Toast.makeText(this, "Push" + "    Player is returned" +  player.getBet() + "  Player now has " + player.getStack(), Toast.LENGTH_SHORT);
		pw.show();
		
		
	}
	public void showbet()
	{
	Toast bet = Toast.makeText(this, String.format("%d", player.getBet()), Toast.LENGTH_SHORT);
    bet.show();
	}
	

public void clearplayer()
{
	for (int i = 0; i < m_player.size()+1; i++)
		{playerimg[i].setImageResource(0);}
	
}

public void checkSplit()
{
	int card0 = m_player.get(0).getValue();
	int card1 = m_player.get(1).getValue();
	
	if (card0 == card1)
	{
		Button button8 = (Button)findViewById(R.id.split);		
		button8.setVisibility(0);
		}
	if (card0 != card1){
		Button button8 = (Button)findViewById(R.id.split);		
		button8.setVisibility(8);
		}
	}

public void doubledown()
{
	int dbet = player.getBet()*2;
	int newstack = player.getStack()-player.getBet();
	player.setStack(newstack);
	player.setBet(dbet);
	hit();
	stay();
}

public void split()
{
    

	 
	 RelativeLayout rl = (RelativeLayout)findViewById(R.id.table1);
     int width = rl.getWidth();
     int maxWidth = width / 5;
     
	 splitplayerimg= new ImageView[5];
     splitplayerimg[0] = (ImageView)findViewById(R.id.splitplayercard1);
     splitplayerimg[1] = (ImageView)findViewById(R.id.splitplayercard2);

     
     splitplayerimg[0].setMaxWidth(maxWidth);
     splitplayerimg[1].setMaxWidth(maxWidth);
	
     s_player.add(m_player.remove(1));
	 s_player.add(deal.DealCard());
	 m_player.add(deal.DealCard());
	 
	 for (int i = 0; i < m_player.size(); i++){
 		{playerimg[i].setImageResource(m_cardIds[m_player.get(i).getValue() * 4 + m_player.get(i).getSuit()]);}
	 }
 	 for (int y = 0; y < s_player.size(); y++){
 	 		{splitplayerimg[y].setImageResource(m_cardIds[s_player.get(y).getValue() * 4 + s_player.get(y).getSuit()]);}	
	 }
	 
	 checkblackjack();
	 checkSplit();
	 
	 
}
public void splitdoubledown()
{
	int dbet = player.getBet()*2;
	int newstack = player.getStack()-player.getBet();
	player.setStack(newstack);
	player.setBet(dbet);
	splithit();
	splitstay();
}
//public void split()
//{
//	 s_player = new ArrayList<Card>();
//	 
//	 RelativeLayout rl = (RelativeLayout)findViewById(R.id.table1);
//     int width = rl.getWidth();
//     int maxWidth = width / 5;
//     
//	 splitplayerimg= new ImageView[5];
//     splitplayerimg[0] = (ImageView)findViewById(R.id.splitplayercard1);
//     splitplayerimg[1] = (ImageView)findViewById(R.id.splitplayercard2);
//
//     
//     splitplayerimg[0].setMaxWidth(maxWidth);
//     splitplayerimg[1].setMaxWidth(maxWidth);
//	
//     s_player.add(m_player.remove(1));
//	 s_player.add(deal.DealCard());
//	 m_player.add(deal.DealCard());
//	 
//	 for (int i = 0; i < m_player.size(); i++){
// 		{playerimg[i].setImageResource(m_cardIds[m_player.get(i).getValue() * 4 + m_player.get(i).getSuit()]);}
//	 }
// 	 for (int y = 0; y < s_player.size(); y++){
// 	 		{splitplayerimg[y].setImageResource(m_cardIds[s_player.get(y).getValue() * 4 + s_player.get(y).getSuit()]);}	
//	 }
//	 
//	 checkblackjack();
//	 checkSplit();
//	 
//	 
//}
public void splitstay()
{

dealerimg[2].setImageResource(m_cardIds[m_dealer.get(0).getValue() * 4 + m_dealer.get(0).getSuit()]);		
int dealscore = getdealersum();


if (dealscore <= 17)
{dealerhit();}
if (dealscore > 21)
{playerwins();}
if (dealscore <= 21 && dealscore > 17)
{splitshowdown();}
showdown();	
}
private void splitshowdown()
{
int dealscore = getdealersum();
int playscore = getsplitsum();

if (playscore > dealscore )
{playerwins();}
if (dealscore > playscore)
{dealerwins();}
if (dealscore == playscore)
{push();}
}

private void aces()
{

for (int i = 0; i < m_player.size(); i++)
	{
	Card card = m_player.get(i);
	int value = card.getValue();
	switch(value){
		
		case 0:
		{ int sum = getsum();
		if (sum > 10)
			{card.setScore(1);
		}
		if (sum <= 10)
			{card.setScore(11);
			}
		}

		}
	}
	

}
public void setbet()
{
final EditText editbet = (EditText)findViewById(R.id.bet);
int bet = Integer.parseInt(editbet.getText().toString());
int stack = player.getStack();
int newstack = stack - bet;
player.setStack(newstack);
player.setBet(bet);
showbet();
}
	
}